package com.guchenbo.scala.c7

import com.guchenbo.scala.Helper

/**
 * @author guchenbo
 * @date 2022/3/21
 */
class Parent {
  var name: String = _

  println("parent主构造器")
  def this(name: String) = {
    this
    println("parent辅助构造器")
    this.name=name
  }
}

class Child extends Parent() {
println("child主构造器")

  def this(age:Int)={
    this
    println("child辅助构造器")
  }

  def this(name:String)={
    this
  }
}

object ParentDemo {
  def main(args: Array[String]): Unit = {
    new Parent
    Helper.div()
    new Parent("abe")
    Helper.div()
    new Child
    Helper.div()
    new Child(18)

    new Child22("b").print()
  }
}

class Parent2(var name:String,var age:Int){
  println("parent2 main")

  def this()={
    this("aa",this.age)
    println("parent2 not main")
  }
  def print(): Unit ={
    println(this.name)
  }
}
class Child2(name:String) extends Parent2(name,12){
  println("child2 main")

}
class Child22(name:String) extends Parent2{

}